package com.zld.smarket.service.serviceImpl;

import com.zld.smarket.dao.StockinMapper;
import com.zld.smarket.dto.StockList;
import com.zld.smarket.dto.StockinList;
import com.zld.smarket.pojo.Stockin;
import com.zld.smarket.result.ResponseData;
import com.zld.smarket.service.StockinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockinServiceImpl implements StockinService{

    @Autowired
    private StockinMapper stockinMapper;

    @Override
    public ResponseData findList(Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }
        List<StockinList> stockinLists = stockinMapper.selectAllAndPage(page,limit);
        Long count = stockinMapper.countstockin();
        return new ResponseData(stockinLists,count);
    }

    @Override
    public ResponseData search(String s, Integer page, Integer limit) {
        if(page != null && limit!=null){
            page = (page-1)*limit;
        }else{
            page = 0;
            limit = 10;
        }

        List<StockinList> stockinLists =  stockinMapper.search(s,page,limit);
        Long count = Long.valueOf(stockinLists.size());
        return new ResponseData(stockinLists,count);
    }

    @Override
    public Long selectbyno(Long stockinNo) {
        return stockinMapper.countbyno(stockinNo);
    }

    @Override
    public Integer addStockin(Stockin stockin) {
        int j=0;
        j=stockinMapper.insert(stockin);
        return j;
    }

    @Override
    public Long weekstockin() {
        return stockinMapper.weekstockin();
    }
}
